<template>
  <div class="comment">
    <!-- 按钮 -->
    <div class="btns">
        <el-form size="small" inline style="text-align:center">
            <el-form-item label="请输入id">
              <el-input v-model.lazy="param.id"></el-input>
            </el-form-item>
            <el-form-item label="请输入内容">
              <el-input v-model.lazy="param.content"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" plain size="small" icon="el-icon-search" @click="loadApplications">搜索</el-button>
              <el-button size="small" type="primary" @click="downloadHandler" icon="el-icon-download">导出</el-button>
              <el-button size="small" type="primary" @click="toAddHandler" icon="el-icon-plus">新增</el-button>
            </el-form-item>
        </el-form>
        <el-form>
            <el-form-item style="box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)">
                <div id="home" style="text-align:center">
                  <span class="deadline" style="font-size:22px">{{ gettime }}</span>
                </div>
                
            </el-form-item>
        </el-form>
        <div class="block">
            <el-carousel :interval="2000" type="card" height="300px">
                <el-carousel-item v-for="item in imagebox" :key="item.id">
                  <img :src="item.idView" class="image" width="100%">
                </el-carousel-item>  
            </el-carousel>
        </div>
        
    </div>
    <!-- /按钮 -->
    <!-- 表格 -->
    
    <el-table size="large" :data="comment">
      <el-table-column label="序号" type="index" :index="1" width="30px"></el-table-column>
      <el-table-column label="id" prop="id" align="center"  width="60px"></el-table-column>
      <el-table-column label="内容" prop="content" align="center" type="textarea" :rows="4" width="450px"></el-table-column>
      <el-table-column label="时间" prop="commentTime" :formatter="setDate" align="center" width="125px"></el-table-column>
      <el-table-column label="状态" prop="status" align="center" width="80px"></el-table-column>
      <el-table-column label="推荐指数" prop="userId" align="center">
            <!-- eslint-disable-next-line -->
            <template slot-scope="scope"> 
            <el-rate
             v-model="value"
             show-text>
          </el-rate>
          </template>
          </el-table-column>
      <el-table-column label="评论日期" align="center">
        <el-date-picker
          v-model="value2"
          align="right"
          type="date"
          placeholder="选择日期"
          :picker-options="pickerOptions" style="width:150px">
        </el-date-picker>
      </el-table-column>

      <el-table-column label="操作" width="200px" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="editHandler(scope.row)" icon="el-icon-edit">修改</el-button>
          <el-button type="danger" size="mini" @click="deleteHandler(scope.row)" icon="el-icon-delete">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);margin:0 auto;width:80%;">
        <el-calendar v-model="value3" style="text-align:center"></el-calendar>
    </div>
    <!-- /表格 -->
    <!-- 模态框 -->
    <!-- /模态框 -->
  </div>
</template>
<script>
import { del , get } from '@/utils/request'
import moment from 'moment'
export default {
    name: "Home",
  // 页面数据
  data(){
    return {
        // 用于保存检索的参数
        param:{},
        // 组件模板中需要的数据
      comment:[],
     value: null,
     value2: null,
     value3: new Date(),
     gettime: "",
      imagebox:[
        {id:0,idView:require("../img/01.png")}, 
        {id:1,idView:require("../img/02.png")},
        {id:2,idView:require("../img/03.png")},
        {id:3,idView:require("../img/04.png")},
        {id:4,idView:require("../img/05.png")},
        {id:5,idView:require("../img/1.gif")}, 

        ],
        screenWidth :0,
    }
  },
  // 所有的方法
  methods:{
    downloadHandler(){
      window.location.href="http://39.101.198.99:8888/comment/download?id="+this.param.id,
      window.location.href="http://39.101.198.99:8888/comment/download?content="+this.param.content

    },
    setDate :function(row, column) {
     var newdata = row[column.property];
     if(newdata == undefined) {return "";}
     return moment(newdata).format("YYYY-MM-DD");
   },

    //     getTime: function () {
    //   var _this = this;
    //   let yy = new Date().getFullYear();
    //   var mm =
    //     new Date().getMonth() < 10
    //       ? "0" + (new Date().getMonth() + 1)
    //       : new Date().getMonth() + 1;
    //   var dd =
    //     new Date().getDate() < 10
    //       ? "0" + new Date().getDate()
    //       : new Date().getDate();
    //   let hh = new Date().getHours();
    //   let mf =
    //     new Date().getMinutes() < 10
    //       ? "0" + new Date().getMinutes()
    //       : new Date().getMinutes();
    //   let ss =
    //     new Date().getSeconds() < 10
    //       ? "0" + new Date().getSeconds()
    //       : new Date().getSeconds();
    //   _this.gettime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
    // },
    currentTime() {
      setInterval(this.getTime, 500);
    },
    // 跳转 
    editHandler(row){
        // 跳转到修改
        // 携带当前行
        this.$router.push({
          path:"/comment/create",
          query:row

        })
    },
        deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://39.101.198.99:8888/comment/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadApplications();
        });
      });
    },

    toAddHandler(){
      this.$router.push("/comment/create")
    },
        // 查询后台中的应用信息
    loadApplications(){
      let url = 'http://39.101.198.99:8888/comment/query'
      get(url,this.param).then((resp)=>{
        this.comment = resp.data;
      })
    }
  },
    mounted() {
    this.created();
  },
   // 页面渲染的时候会调用的函数
  created(){
    this.loadApplications();
    this.currentTime();
  }
}
</script>
<style scoped>
.btns {
  margin-bottom: .5em;
}
</style>

//走马灯
<style>
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
  }
  
</style>